package com.spider;

import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.HttpStatus;
import com.httpclient.SpiderHttpClientManager;


public class SST_callPhone {

/**
 * 随身通 自动拨号业务
 */	
	
public static void main(String[] args){
		post("7962");
	}
	
	private static void post(String c){
		HttpClient http = SpiderHttpClientManager.getInstance();
		PostMethod post = new PostMethod("http://www.skymeetings.net/login.htm");
		/**设置 post 提交数据*/
		NameValuePair[] data = new NameValuePair[5];
		data[0] = new NameValuePair("loginid","23023081");
		data[1] = new NameValuePair("password","862124");
		data[2] = new NameValuePair("code",c);
		data[3] = new NameValuePair("Image2.x","44");
		data[4] = new NameValuePair("Image2.y","9");
		post.setRequestBody(data);
		
		/**设置 post 头部信息*/
		post.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		post.setRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
		post.setRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
		post.setRequestHeader("Accept-Language", "en-US,en;q=0.8");
		post.setRequestHeader("Cache-Control", "max-age=0");
		post.setRequestHeader("Connection", "keep-alive");
		post.setRequestHeader("Cookie", "pgv_pvi=4758189056; JSESSIONID=04663278CBA4023CF6F12F150ED4BFC2; pgv_si=s4937266176");
		post.setRequestHeader("Host", "www.skymeetings.net");
		post.setRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11");
		
		try {
			int code = http.executeMethod(post);
			if(code==HttpStatus.SC_MOVED_TEMPORARILY){
				System.out.println("正在 正在进行……");
				codYourNumber();
			}else{
				String content = post.getResponseBodyAsString();
				System.out.println(content);
			}
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	    
	
	private static void codYourNumber(){
		HttpClient http = SpiderHttpClientManager.getInstance();
		PostMethod post = new PostMethod("http://www.skymeetings.net/initdial.htm");
		NameValuePair[] data = new NameValuePair[3];
		data[0] = new NameValuePair("m","13269712016");
		data[1] = new NameValuePair("ms","15037103053");
		data[2] = new NameValuePair("mid","");
		post.setRequestBody(data);
		
		post.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		post.setRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
		post.setRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
		post.setRequestHeader("Accept-Language", "en-US,en;q=0.8");
		post.setRequestHeader("Cache-Control", "max-age=0");
		post.setRequestHeader("Connection", "keep-alive");
		post.setRequestHeader("Cookie", "pgv_pvi=4758189056; JSESSIONID=04663278CBA4023CF6F12F150ED4BFC2; pgv_si=s4937266176");
		post.setRequestHeader("Host", "www.skymeetings.net");
		post.setRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11");
		
		try {
			int code = http.executeMethod(post);
			if(code==HttpStatus.SC_OK){
				System.out.println("拨号成功！");
			}else{
				System.out.println("拨号失败……");
			}
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
